<template>
  <div class="home" style="height:100%">
    <van-search
      v-model="searchCount"
      placeholder="请输入搜索关键词"
      show-action
      @search="onSearch"
      style="margin-bottom:20px"
    >
      <div slot="action" @click="onSearch">搜索</div>
    </van-search>
    <van-button size="small" type="primary" round  v-for="j in hotSearch" :key="j" style="margin:5px" @click="href(j)">{{j}}</van-button>
  </div>
</template>

<script>
// @ is an alias to /src
import { searchall } from "../api/getHistory";

export default {
  name: "home",
  data: function() {
    return {
      src: "",
      searchCount:'',
      hotSearch:[],
      history:[]
    };
  },
  components: {},
  mounted() {
    
  },
  methods: {
    onSearch() {
      searchall(this.searchCount).then((data) =>{
        if(data.data.length != 0){
          this.hotSearch = data.data
          //this.$router.push(`/detail?name=${data.data.data.name}&key=${data.data.data.type}`)
        }else{
           this.$toast.fail('查询内容不存在');
        }
      })
    },
    href(name){
        this.$router.push(`/detail?name=${name}`)
    },
  }
};
</script>
<style lang="scss" scoped>
.home{
  background: #ffffff;
}
.historys{
  width: 95%;
  margin: 0 auto;
  margin-top: 20px;
  h3{
    font-size: 16px;
    line-height: 32px;
    margin-top: 10px;
    margin-left: 10px;
  }
}
</style>
